import turtle

# 设置画布和画笔
screen = turtle.Screen()
screen.title("可爱的小猫")
pen = turtle.Turtle()
pen.speed(3)  # 绘制速度
pen.pensize(2)  # 画笔粗细

# 绘制头部
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.color("#FFD700")  # 金黄色
pen.begin_fill()
pen.circle(100)  # 头部是一个圆形
pen.end_fill()

# 绘制耳朵
def draw_ear(x, y):
    """绘制猫耳朵的函数"""
    pen.penup()
    pen.goto(x, y)
    pen.pendown()
    pen.color("#FFD700")
    pen.begin_fill()
    pen.setheading(0)
    pen.forward(30)
    pen.setheading(60)
    pen.forward(40)
    pen.setheading(180)
    pen.forward(30)
    pen.end_fill()
    # 耳朵内侧
    pen.penup()
    pen.goto(x + 5, y + 5)
    pen.pendown()
    pen.color("#FFA07A")  # 浅橙色
    pen.begin_fill()
    pen.setheading(0)
    pen.forward(20)
    pen.setheading(60)
    pen.forward(30)
    pen.setheading(180)
    pen.forward(20)
    pen.end_fill()

# 绘制左右耳朵
draw_ear(-50, 30)
draw_ear(20, 30)

# 绘制眼睛
def draw_eye(x, y):
    """绘制猫眼的函数"""
    pen.penup()
    pen.goto(x, y)
    pen.pendown()
    pen.color("white")
    pen.begin_fill()
    pen.circle(15)
    pen.end_fill()
    # 瞳孔（垂直椭圆）
    pen.penup()
    pen.goto(x, y - 3)
    pen.pendown()
    pen.color("black")
    pen.begin_fill()
    for _ in range(2):
        pen.circle(8, 90)  # 绘制椭圆
        pen.circle(4, 90)
    pen.end_fill()

# 绘制左右眼
draw_eye(-30, 20)
draw_eye(30, 20)

# 绘制鼻子
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.color("#FF6347")  # 番茄红
pen.begin_fill()
pen.setheading(30)
pen.forward(15)
pen.setheading(150)
pen.forward(15)
pen.setheading(270)
pen.forward(15)
pen.end_fill()

# 绘制嘴巴
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.color("black")
pen.width(1)
pen.setheading(270)
pen.forward(10)
pen.setheading(300)
pen.forward(20)
pen.penup()
pen.goto(0, -10)
pen.pendown()
pen.setheading(240)
pen.forward(20)

# 绘制胡须
def draw_whiskers(x):
    """绘制胡须的函数，x为左右方向"""
    positions = [-10, 0, 10]  # 三个高度位置
    lengths = [30, 40, 30]    # 对应长度
    for i in range(3):
        pen.penup()
        pen.goto(x, positions[i])
        pen.pendown()
        pen.setheading(0 if x > 0 else 180)
        pen.forward(lengths[i])

# 绘制左右胡须
draw_whiskers(-15)  # 左胡须
draw_whiskers(15)   # 右胡须

# 隐藏画笔
pen.hideturtle()

# 保持窗口打开
screen.mainloop()
    